package com.hotchpotch.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;


import com.hotchpotch.R;
import com.hotchpotch.bean.CategoryChildBean;
import com.hotchpotch.custom.MyCustomGridview;

import java.util.List;

/**
 * Created by Administrator on 2017/5/17 0017.
 */

public class ClassificationRightAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<CategoryChildBean.ResultBean> list;

    public ClassificationRightAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<CategoryChildBean.ResultBean> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_classification_right, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final CategoryChildBean.ResultBean resultBean = list.get(position);
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).textViewTitle.setText(resultBean.cat_name);
            ClassificationRightGridViewAdapter adapter = new ClassificationRightGridViewAdapter(context, resultBean.date);
            ((ViewHolder) holder).gridview.setAdapter(adapter);
            ((ViewHolder) holder).gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    /*Intent intent = new Intent(context, ClassificationActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("id", resultBean.date.get(position).cat_id);
                    bundle.putString("name", resultBean.date.get(position).cat_name);
                    intent.putExtras(bundle);
                    context.startActivity(intent);*/
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {
        private TextView textViewTitle;
        private MyCustomGridview gridview;

        public ViewHolder(View itemView) {
            super(itemView);
            textViewTitle = (TextView) itemView.findViewById(R.id.item_classification_right_title);
            gridview = (MyCustomGridview) itemView.findViewById(R.id.item_classification_right_gridview);
        }
    }
}
